package xyvcard;

public class Main {
  public static void main(String[] args) throws Exception {
    String sourceCode =
        "public class HelloWorld {\n" + "    public static  void main(String[] args) {\n"
            + "        System.out.println(\"Hello, World from Memory!\");\n" + "    }\n" + "}\n";
 // 编译目录,默认当前目录
    String outputDir = "."; 

    CompileResult result = JavaCompilerHelper.compileFromString(sourceCode, outputDir);
    if (result.isSuccess()) {
      System.out.println("编译成功");
      // 动态运行编译后的字节码
      RunResultWithOutput rr= JavaExecutor.executeClassAndCaptureOutput(result.getClassName(), outputDir);
      System.out.println("执行结果:"+rr.getOutput());
    } else {
      System.err.println(result.getMessage());
    }
  }
}
